package com.baizhi.controller;

import com.baizhi.service.ThreadUserService;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 野马 on 2019/6/17.
 */

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private ThreadUserService threadUserService;

    @RequestMapping("/selectUser")
    @ResponseBody
    public Map selectUser(String userName,int page,int rows){

        return userService.selectUser(userName, page, rows);

    }
    //没有优前
    @RequestMapping("/selectSex")
    @ResponseBody
    public Map selectSex(){
        Map map = new HashMap();
        long start = System.currentTimeMillis();
        List<Map> selectGroupBySex = userService.selectGroupBySex();
        List<Map> selectGroupBySF = userService.selectGroupBySF();
        map.put("Sex",selectGroupBySex);
        map.put("SF",selectGroupBySF);
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms"+"没有优化");
        return map;
    }

    @RequestMapping("selectYH")
    @ResponseBody
    public Map selectYH() throws Exception{
        long start = System.currentTimeMillis();
        Map map = threadUserService.getAllCountByFuture();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms"+"优化");
        return map;
    }

    @RequestMapping("selectYHH")
    @ResponseBody
    public Map selectYHH() throws Exception {
        long start = System.currentTimeMillis();
        Map map = threadUserService.getAllCountByCountDownLatch();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms"+"优化Runnable");
        return map;
    }





}
